package com.aest.execution.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.aest.common.annotation.Log;
import com.aest.common.core.controller.BaseController;
import com.aest.common.core.domain.AjaxResult;
import com.aest.common.enums.BusinessType;
import com.aest.execution.domain.ExecutionRecord;
import com.aest.execution.service.IExecutionRecordService;
import com.aest.common.utils.poi.ExcelUtil;
import com.aest.common.core.page.TableDataInfo;

/**
 * 任务执行记录Controller
 * 
 * @author Lanwen.jc
 * @date 2025-07-31
 */
@RestController
@RequestMapping("/execution/ExecuteRecord")
public class ExecutionRecordController extends BaseController
{
    @Autowired
    private IExecutionRecordService executionRecordService;

    /**
     * 查询任务执行记录列表
     */
    @PreAuthorize("@ss.hasPermi('execution:ExecuteRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExecutionRecord executionRecord)
    {
        startPage();
        List<ExecutionRecord> list = executionRecordService.selectExecutionRecordList(executionRecord);
        return getDataTable(list);
    }

    /**
     * 导出任务执行记录列表
     */
    @PreAuthorize("@ss.hasPermi('execution:ExecuteRecord:export')")
    @Log(title = "任务执行记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExecutionRecord executionRecord)
    {
        List<ExecutionRecord> list = executionRecordService.selectExecutionRecordList(executionRecord);
        ExcelUtil<ExecutionRecord> util = new ExcelUtil<ExecutionRecord>(ExecutionRecord.class);
        util.exportExcel(response, list, "任务执行记录数据");
    }

    /**
     * 获取任务执行记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('execution:ExecuteRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(executionRecordService.selectExecutionRecordById(id));
    }

    /**
     * 新增任务执行记录
     */
    @PreAuthorize("@ss.hasPermi('execution:ExecuteRecord:add')")
    @Log(title = "任务执行记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExecutionRecord executionRecord)
    {
        executionRecord.setUserName(getUsername());
        return toAjax(executionRecordService.insertExecutionRecord(executionRecord));
    }

    /**
     * 修改任务执行记录
     */
    @PreAuthorize("@ss.hasPermi('execution:ExecuteRecord:edit')")
    @Log(title = "任务执行记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExecutionRecord executionRecord)
    {
        return toAjax(executionRecordService.updateExecutionRecord(executionRecord));
    }

    /**
     * 删除任务执行记录
     */
    @PreAuthorize("@ss.hasPermi('execution:ExecuteRecord:remove')")
    @Log(title = "任务执行记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(executionRecordService.deleteExecutionRecordByIds(ids));
    }
}
